package com.controller;

import com.model.MyUser;
import com.service.MyuserServicelmpl;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("我的用户")
@RestController
@RequestMapping("/myUser")
public class MyuserController {
    @Autowired
    private MyuserServicelmpl myuserService;
    @RequestMapping(value = "/addUser",produces = "application/json;charset=utf-8",method = RequestMethod.GET)
    public int addUser(MyUser myUser)
    {
        System.out.println("进入用户添加方法");
        return myuserService.addMyUser(myUser);
    }
    @RequestMapping(value = "updataMyuser",produces = "application/json;charset=utf-8",method = RequestMethod.GET)
    public int updateUser(MyUser myUser)
    {
        System.out.println("进入用户修改方法，修改的主键为"+myUser.getRegisterID());
        return myuserService.updateMyUser(myUser);
    }
    @RequestMapping(value = "/deleteUser",produces = "application/json;charset=utf-8",method = RequestMethod.GET)
    public int deleteMyser(int registerID)
    {
        System.out.println("进入删除用户信息，主键为："+registerID);
        return myuserService.deleteMyUser(registerID);
    }
    @RequestMapping(value = "/getUser",produces = "application/json;charset=utf-8",method = RequestMethod.GET)
    public MyUser getUser(int registerID)
    {
        System.out.println("进入根据主键查找用户信息，主键为："+registerID);
        return myuserService.getUser(registerID);
    }
    //解决跨越问题
    @CrossOrigin
    @RequestMapping(value = "/getAll",produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
    public List<MyUser> getAll(@RequestBody MyUser myuser)
    {
        System.out.println("进入用户查询方法");
        System.out.println(myuser.getRegisterID()+"======="+myuser.getTime());
        return myuserService.getAllMyUsers(myuser);
    }
}